#ifndef _ERROR_CHECK_
#define _ERROR_CHECK_

#include <iomanip>
#include <iostream>
#include <list>
#include <stdio.h>
#include "math.h"
using namespace std;

#define ERROR_THRESHOLD_V (0.000001)
#define ERROR_THRESHOLD_P (0.001)


class ErrorMsg {
	int index;
	float value1;
	float value2;
	float error_value;
public:
	ErrorMsg(int idx, float v1, float v2, float error) {
	   index = idx;
	   value1 = v1;
	   value2 = v2;
	   error_value = error;
	}

	void print_p() {
		cout<<"error data at ["<<(index/512)<<","<<(index%512)<<"] ("<<setprecision(10)<<value1<<","<<value2<<")"<<" error per "<<setprecision(10)<<error_value<<endl;
	}

	void print_v() {
		cout<<"error data at ["<<index<<"] error diff "<<setprecision(9)<<error_value<<endl;
	}
};


class ErrorChecker {
public:
    ErrorChecker() {}
    void check_textfile(FILE *fHandle1, FILE *fHandle2, unsigned int size);
    void check_data(float *data1, float *data2, unsigned int size);

    void add_error_msg_p(ErrorMsg msg) { error_messages_p.push_back(msg); }
    void add_error_msg_v(ErrorMsg msg) { error_messages_v.push_back(msg); }
    
    void dump_error_p() 
    {
            cout << "percent error messges list: "<<endl;
            list<ErrorMsg>::iterator p = error_messages_p.begin();
            while(p != error_messages_p.end()) {
                p->print_p();
                p++;
            }
            cout << endl; 
    }
  
private:
    list<ErrorMsg> error_messages_p;
    list<ErrorMsg> error_messages_v;
};


#endif
